﻿// 计算⼀下A/B/C实例化的对象的大小
#include<iostream>
using namespace std;
class A
{
public:
	void Print()
	{
		cout << "Print()" << endl;
	}
private:
	char _ch;
	int _i;
};

class B
{
public:
	void Print()
	{
		cout << "Print()" << endl;
	}
};

class C
{};

int main()
{
	A a;
	B b;
	C c;
	cout << sizeof(a) << endl;
	cout << sizeof(b) << endl;
	cout << sizeof(c) << endl;
	return 0;
}


// this指针
#include<iostream>
using namespace std;
class Date
{
public:
	// void Init(Date* const this, int year, int month, int day)
	void Init(int year, int month, int day)
	{
		_year = year;
		_month = month;
		_day = day;
		// 成员函数中调用另一个成员函数，若未指定调用对象会默认传this指针
		Print();// Print(this);
	}

	void Print()// void Print(Date* const this)
	{
		cout << _year << "/" << _month << "/" << _day << endl;
	}
private:
	int _year;
	int _month;
	int _day;
};
int main()
{
	// Date类实例化出对象d1和d2
	Date d1;
	Date d2;
	
	d1.Init(2024, 3, 31);// d1.Init(&d1, 2024, 3, 31);

	d2.Init(2024, 7, 5);// d2.Init(&d2, 2024, 7, 5);
	return 0;
}